using System;
using Sce.PlayStation.Core;

namespace Nyanimals
{
	public class CNyanimalIdleState : CNyamimalBaseState
	{
        private float idleTime;
        private float curTime;
        private bool bStuck;
        
		public CNyanimalIdleState(string szName, CNyanimal nyan) : base(szName, nyan)
		{
		}
  
        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="Nyanimals.CNyanimalIdleState"/> is stuck in this state.
        /// </summary>
        /// <value>
        /// <c>true</c> if stuck; otherwise, <c>false</c>.
        /// </value>
        public bool Stuck
        {
            get { return bStuck;}
            set { bStuck = value;}
        }
        
		public override void Enter ()
		{
			Nyaminal.ChangeAnimation("idle");
            idleTime = (float)CRandom.Next(100, 500) / 100.0f; // 1sec to 5sec
            curTime = 0.0f;
            bStuck = false;
			//Console.WriteLine("NyanimalIdleState::Enter()");
		}

		public override void Exit ()
		{
			//Console.WriteLine("NyanimalIdleState::Exit()");
		}

		public override void Input ()
		{		
		}

		public override void Update (float deltaTime)
		{
            // only leave the state randomly when we are not stuck
            if(bStuck == false)
            {
                curTime += deltaTime;
                if(curTime >= idleTime)
                {
                    Nyaminal.NewDecision();
                }
            }
		}
	}
}

